% 适用于十进制的单点交叉算法
function children = GA_singlePointCrossoverAndMutation(parent1,parent2,crossoverRate,mutationRate)
    global Encode_BitNum  OptimizationVariableNum %使用全局变量有误
    %BitNum = 12;OptimizationVariableNum=6;
    parent1_dec = GA_Encode(parent1);
    parent2_dec = GA_Encode(parent2);
    % 目前变量一致可以使用，如果维数不同，不可使用
    parent1_bin = dec2bin(parent1_dec,Encode_BitNum(1));
    parent2_bin = dec2bin(parent2_dec,Encode_BitNum(1));
    child1_bin = parent1_bin;
    child2_bin = parent2_bin;
    % 交叉操作，按变量分别进行交换
    for i = 1:1:OptimizationVariableNum
        % 交换
        BitNum_t = Encode_BitNum(i);
        if rand < crossoverRate 
            crossoverPoint = randi(BitNum_t - 1);
            child1_bin(i,:) = [parent1_bin(i,1:crossoverPoint),parent2_bin(i,crossoverPoint+1:BitNum_t)];
            child2_bin(i,:) = [parent2_bin(i,1:crossoverPoint),parent1_bin(i,crossoverPoint+1:BitNum_t)];
        else
            child1_bin(i,:) = parent1_bin(i,1:BitNum_t);
            child2_bin(i,:) = parent2_bin(i,1:BitNum_t);
        end
            % 变异
        for j = 1:1:BitNum_t
            if rand < mutationRate
                % 反转
                if child1_bin(i,j) == '1'  % 对二进制染色体进行反转
                   child1_bin(i,j) = '0';
                else 
                   child1_bin(i,j) = '1';
                end
            end
        end
    end
    % 转换为10进制
    child1_dec = bin2dec(child1_bin).';
    child2_dec = bin2dec(child2_bin).';
    % 对交换和变异后的进行编码
    child1 = GA_Decode(child1_dec);
    child2 = GA_Decode(child2_dec);
    children = [child1;child2];
end